package cc.fs.study.hotfix;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.io.File;
import java.io.IOException;

import cc.fs.study.App;
import cc.fs.study.R;

/**
 * 热修补技术 demo 使用AndFix技术:https://github.com/alibaba/AndFix
 */
public class HotFixActivity extends AppCompatActivity {

    Button btn,btn2;
    String patchPath = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_fix);

        ((TextView) findViewById(R.id.text)).setText("存在bug");

        final File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "StudyPatch" + File.separator);
        if (!file.exists()) {
            file.mkdir();
        }

        Log.e("-补丁程序-", file.getAbsolutePath());


        btn = (Button) findViewById(R.id.btn);
        btn2 = (Button) findViewById(R.id.btn2);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    App.instance.addPatch((new File(file.getAbsolutePath()+File.separator+"fixhotfixactivity.apatch")).getAbsolutePath());
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e("-补丁程序-", "--打补丁失败--");
                }
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                App.instance.cleanPatch();
            }
        });
    }
}
